package com.shyfu.entities;

import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "ROLES", schema = "SHYFU", catalog = "")
public class Role {
    private long userRoleId;
    @NotNull
    @NotEmpty
    @Size(max = 100)
    private String authority;
    private User user;

    @Id
    @Column(name = "USER_ROLE_ID", nullable = false, insertable = true, updatable = true, precision = 0)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_seq")
    @SequenceGenerator(name = "role_seq", sequenceName = "ROLEIDSEQUENCE", allocationSize = 1)
    public long getUserRoleId() {
        return userRoleId;
    }

    public void setUserRoleId(long userRoleId) {
        this.userRoleId = userRoleId;
    }

    @Basic
    @Column(name = "AUTHORITY", nullable = false, insertable = true, updatable = true, length = 100)
    public String getAuthority() {
        return authority;
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }

    @ManyToOne
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Role role = (Role) o;

        if (userRoleId != role.userRoleId) return false;
        if (authority != null ? !authority.equals(role.authority) : role.authority != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        long result = userRoleId;
        result = 31 * result + (authority != null ? authority.hashCode() : 0);
        return ((Long) result).intValue();
    }
}
